package com.lechuang.system.controller;

import com.lechuang.common.request.PageRequest;
import com.lechuang.common.result.PageResult;
import com.lechuang.common.result.Result;
import com.lechuang.system.dto.TenantSaveDTO;
import com.lechuang.system.dto.TenantListDTO;
import com.lechuang.system.manager.TenantManager;
import com.lechuang.system.vo.TenantDetailVO;
import com.lechuang.system.vo.TenantListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tenant")
@Tag(name = "商户")
public class TenantController {

    @Resource
    private TenantManager tenantManager;

    @PostMapping("/pageList")
    @Operation(summary = "商户列表")
    public Result<PageResult<TenantListVO>> pageList(@RequestBody PageRequest<TenantListDTO> pageRequest){
        PageResult<TenantListVO> list = tenantManager.pageList(pageRequest);
        return Result.success(list);
    }

    @PostMapping("/saveAndUpdate")
    @Operation(summary = "新增、修改商户")
    public Result<Object> saveAndUpdate(@RequestBody TenantSaveDTO tenantSaveDTO){
        tenantManager.saveAndUpdate(tenantSaveDTO);
        return Result.success();
    }

    @PostMapping("/detail")
    @Operation(summary = "详情")
    public Result<TenantDetailVO> detail(@RequestParam Long id){
        TenantDetailVO detailVO = tenantManager.detail(id);
        return Result.success(detailVO);
    }

    @PostMapping("/getByNameOrPhone")
    @Operation(summary = "根据名称或者手机号查找")
    public Result<List<TenantListVO>> getByNameOrPhone(@RequestParam String selectText){
        List<TenantListVO> list = tenantManager.getByNameOrPhone(selectText);
        return Result.success(list);
    }

}
